//
//  PictureCell.m
//  weibo-OC
//
//  Created by diyuyma on 16/3/22.
//  Copyright © 2016年 zhangkaiyun. All rights reserved.
//

#import "PictureCell.h"
#import "Masonry.h"
#import "UIImageView+WebCache.h"

@interface PictureCell ()
@property (nonatomic, strong)UIImageView *imageView;

@end

@implementation PictureCell

- (void)setUrl:(NSURL *)url {
    [self.imageView sd_setImageWithURL:url placeholderImage:nil];
}

// MARK: 3.重写父类的构造方法 调用设置 UI
- (instancetype)initWithFrame:(CGRect)frame {    
    self = [super initWithFrame:frame];
    [self setupUI];
    return self;
}


// MARK: 2.设置 UI
- (void)setupUI {
    // 添加子控件
    [self.contentView addSubview:self.imageView];
    
    // 设置约束
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.contentView.mas_top);
//        make.left.equalTo(self.contentView.mas_left);
//        make.right.equalTo(self.contentView.mas_right);
//        make.bottom.equalTo(self.contentView.mas_bottom);
        make.edges.insets(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
}

// MARK: 1.懒加载所有子控件
- (UIImageView *)imageView {
    if (_imageView == nil) {
        UIImageView *iv = [[UIImageView alloc] init];
        // 设置图片显示样式
        iv.contentMode = UIViewContentModeScaleAspectFill;
        // 手写代码 必须自己手动添加 剪裁
        iv.clipsToBounds = true;
        _imageView = iv;
    }
    return _imageView;
}
@end
